package com.jiayang.hhotel.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jiayang.hhotel.R;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2017/6/5 0005.
 * 实名认证页面列表适配器
 */

public class RealNameListAdapter extends BaseAdapter {

    private Context t;
    private List<String> mNameList;
    private List<String> mContentList;
    private HashMap<String,String> values;

    public RealNameListAdapter(Context context,List<String> nameList,List<String> contentList){
        this.t = context;
        this.mNameList = nameList;
        this.mContentList = contentList;
    }
    @Override
    public int getCount() {
        return mContentList.size();
    }

    @Override
    public Object getItem(int position) {
        return mContentList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null){
            convertView= LayoutInflater.from(t).inflate(R.layout.real_name_list_item,null);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        holder= (ViewHolder) convertView.getTag();
        holder.title.setText(mNameList.get(position));
        holder.content.setText(mContentList.get(position));
        return convertView;
    }
    //获取将name:value 的两个集合转换为hashmap的对象
    public HashMap<String,String> getContent(){
        if(values == null)
            values = new HashMap<>();
        for(int i=0;i<mContentList.size();i++){
            values.put(mNameList.get(i),mContentList.get(i));
        }
        return values;
    }

    class ViewHolder{
        TextView title;
        TextView content;
        public ViewHolder(View item){
            title = (TextView) item.findViewById(R.id.tv_title);
            content = (TextView) item.findViewById(R.id.tv_content);
        }
    }
}
